<template>
	<view class="">
		<view class="listitem" @click="goFriend(item)">
			<template v-if="isShow">
				<view class="listitem__left">
					<cl-avatar :src="item.avatar_url" size="100rpx"></cl-avatar>
				</view>
				<view class="listitem__right">
					<view class="listitem__right__top">
						<text class="listitem__right__top__nickname u-line-1" >{{item.friend_remark || item.nick_name}}</text>
						<text v-if="item.user_type && item.user_type > 0 && item.user_type != 6 && item.user_type != 8"
							class="typetag" style="background-color: #02D478;">{{$t('common.friend.authority')}}</text>
					</view>
					<view class="listitem__right__content">
						<text v-if="friendOnline[item.friend_idx]"
							style="color: #6aaf76;font-size: 24rpx;">[{{$t("common.friend.online")}}]</text>
						<text v-else style="color: #595A66;font-size: 24rpx;">[{{$t("common.friend.offline")}}]</text>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		name: 'friend_group_item',
		data() {
			return {
				isShow:true
			}
		},
		props: {
			index: {
				type: Number,
				default: function() {
					return 0
				}
			},
			item: {
				type: Object,
				default: function() {
					return {}
				}
			},
		},
		computed: {
			...mapState({
				friendOnline: state => state.friends.friendOnline,
			}),
		},
		mounted() {
			  // this.createIntersectionObserver();
		},
		methods: {
			goFriend(item) {
				this.$Router.push({
					name: 'friend_details',
					params: {
						friend_idx: item.friend_idx,
						friend_remark: item.friend_remark,
						nick_name: item.nick_name,
						avatar_url: item.avatar_url
					}
				});
			},
			// createIntersectionObserver() {
			//   this.$nextTick(() => {
			// 	  this.$nextTick(() => {
			// 		this.observer = uni.createIntersectionObserver(this);
			// 		this.observer.relativeToViewport().observe('.listitem', (res) => {
			// 			console.log(res);
			// 		  if (res.intersectionRatio > 0) {
			// 			 this.isShow = true
			// 		  } else {
			// 			 this.isShow = false
			// 		  }
			// 		});
			// 	  });
			//   });
			// }
		},
	};
</script>

<style scoped lang="scss">
	.typetag {
		white-space: nowrap;
		font-size: 20rpx;
		color: #FFFFFF;
		padding: 0 10rpx;
		height: 28rpx;
		margin-left: 10rpx;
		line-height: 28rpx;
		text-align: center;
		border-radius: 10rpx;
		background-color: #FF7676;
	}

	.listitem {
		display: flex;
		align-items: center;
		padding: 12rpx 0;
		position: relative;
		height: 124rpx;
		box-sizing: content-box;
		&.active {
			background-color: #ffffff;
		}
		&::after {
			content: "";
			position: absolute;
			width: calc(100% - 130rpx);
			background-color: #e1e1e1;
			height: 1rpx;
			bottom: 0;
			right: 0;
		}

		&__right {
			margin-left: 20rpx;
			flex: 1;

			&__top {
				display: flex;
				align-items: center;

				&__nickname {
					font-size: 28rpx;
				}

				&__time {
					color: #61626E;
					font-size: 20rpx;
				}
			}

			&__content {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 15rpx;

				&__msg {
					flex: 1;
					font-size: 24rpx;
					color: #595A66;
				}
			}
		}
	}
</style>